package net.maku.utils;

import java.nio.file.Paths;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class CodeGenerator {
	
	public static void tmain( String tbname ) {
		
		String url = "jdbc:mysql://127.0.0.1:3306/maku_generator?characterEncoding=utf-8&useUnicode=true&serverTimezone=UTC";
		String username = "jishu";
		String password = "jishu";
		FastAutoGenerator.create( url, username, password )
        .globalConfig(builder -> builder
                .author("yanyh")
                //.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                .outputDir( "D:/generator/duxinai/")
                .commentDate("yyyy-MM-dd")
        )
        .packageConfig(builder -> builder
                .parent("com.baomidou.mybatisplus")
                .entity("entity")
                .mapper("mapper")
                .service("service")
                .serviceImpl("service.impl")
                .xml("mapper.xml")
        )
        .strategyConfig(builder -> {
	        //builder.addInclude("t_apply_join"); // 设置需要生成的表名
	    	builder.controllerBuilder().enableHyphenStyle();  	// 开启驼峰转连字符
	    	builder.entityBuilder().enableLombok();				// 使用lombok
	    	builder.controllerBuilder().enableHyphenStyle()  	// 增加 controller 注解
	    	.enableRestStyle();		//开启RestController
	    	builder.addInclude( tbname ).addTablePrefix("t_", "c_"); // 设置过滤表前缀
        })
        //.strategyConfig(builder -> builder
        //        .entityBuilder()
        //        .enable
        .templateEngine(new FreemarkerTemplateEngine())
        .execute(); 
        //)
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		tmain("gen_test_student");
	}

}
